package tree;

public class BinaryTreeNode<T> extends TreeNode<T> {
	
	private BinaryTreeNode<T> parent;
	
	public BinaryTreeNode(T element) {
		super(element);
	}
	
	public BinaryTreeNode(T element, BinaryTreeNode<T> parent) {
		super(element);
		this.parent = parent;
	}
	
	public BinaryTreeNode(T element, BinaryTreeNode<T> left, BinaryTreeNode<T> right) {
		super(element);
		this.children.set(0, left);
		this.children.set(1, right);
	}
	
	public void setParent(BinaryTreeNode<T> parent) {
		this.parent = parent;
	}
	
	public BinaryTreeNode<T> getParent() {
		return this.parent;
	}
	
	public void setLeft(BinaryTreeNode<T> child) {
		if(this.children.isEmpty())
			this.children.add(child);
		else
			this.children.set(0, child);
	}
	
	public void setRight(BinaryTreeNode<T> child) {
		if(this.children.isEmpty())
			this.children.add(null);
		if(this.children.size()==1)
			this.children.add(child);
		else
			this.children.set(1, child);
	}
	
	public BinaryTreeNode<T> getLeft() {
		return (BinaryTreeNode<T>) this.children.get(0);
	}
	
	public BinaryTreeNode<T> getRight() {
		return (BinaryTreeNode<T>) this.children.get(1);
	}

}
